<?php
/**
 * Created by PhpStorm.
 * User: *!N.J
 * Date: 2021/9/14
 * Time: 22:59
 * QQ:1467572213
 */

namespace app\agent\controller;

use think\facade\Request;
use think\facade\Session;
use \app\agent\model\Order as Order_m;

class Order extends Base
{
    public function order_list()
    {
        $agent_id = Session::get('agent_id');
        $keyword = Request::get('keyword');
        $list = Order_m::order_list($agent_id,$keyword);
        $page = $list->render();
        $this->assign('pages', $page);
        $this->assign('list', $list);
        return $this->fetch();
    }

    //订单续期
    public function order_rollover()
    {
        if (Request::isPost()) {
            $id = Request::post('id');
            $hour = Request::post('hour');
            $order_rollover = Order_m::order_rollover($id, $hour);
            switch ($order_rollover) {
                case 'success':
                    return ['code' => 1, 'msg' => '续期成功'];
                    break;
                case 'error':
                    return ['code' => 0, 'msg' => '系统错误'];
                    break;
            }
        }
    }

    //订单解冻
    public function order_release()
    {
        if (Request::isPost()) {
            $id = Request::post('id');
            $order_release = Order_m::order_release($id);
            switch ($order_release) {
                case 'success':
                    return ['code' => 1, 'msg' => '解冻成功'];
                    break;
                case 'error':
                    return ['code' => 0, 'msg' => '系统错误'];
                    break;
            }
        }
    }

    //新增订单_商品列表
    public function order_add($oid = 0)
    {
        if ($oid){
            $goods_name = trim(Request::get('goods_name'));
            $money_min = trim(Request::get('money_min'));
            $money_max = trim(Request::get('money_max'));
            $goods_list = Order_m::get_goods_list($goods_name,$money_min,$money_max);
            $page = $goods_list->render(); //分页数据
            $this->assign('pages', $page);
            $this->assign('datalist', $goods_list);
            $this->assign('oid',$oid);
            return $this->fetch();
        }else{
            $this->error('参数错误');
        }
    }

    public function add()
    {
        if (Request::isPost()) {
            $oid = Request::post('oid');
            $goods_id = Request::post('goods_id');
            $goods_id = explode(',',$goods_id);
            $add = Order_m::add($oid,$goods_id);
            if ($add == 'success'){
                return ['code'=>1,'msg'=>'添加成功'];
            }else{
                return ['code'=>0,'msg'=>'添加失败'];
            }
        }
    }

    public function order_del()
    {
        if (Request::isPost()){
            $id = Request::post('id');
            $del = Order_m::order_del($id);
            switch ($del)
            {
                case 'success':
                    return ['code'=>1,'msg'=>'删除成功'];
                    break;
                case 'error':
                    return ['code'=>0,'msg'=>'删除失败'];
                    break;
            }
        }
    }

}